// 树转list
const json = {
  a: { b: { c: 1 } },
  d: [1, 2],
};



// const dfs = (root, path = []) => {
//   if(typeof root === 'object'){
//     Object.keys(root).forEach(k => {
//       dfs(root[k], [...path, k])
//     })
//   }else{
//     result.set(path, root)
//   }
// }

const bfs = (root) => {
  let result = new Map
  const o = {
    v: root,
    path: []
  }
  let q = [o]
  
  while(q.length > 0){
    const m = q.shift()

    const v = m.v
    if(typeof v === 'object'){
      Object.keys(v).forEach(k => {
        const p = v[k]
        q.push({
          v: p,
          path: [...m.path, k]
        })
      })
    }else{
      result.set(m.path, v)
    }

  }

  return result
}



console.log(bfs(json))